Difference Between an Array and an Object in JavaScript

In JavaScript, both arrays and objects are used to store collections of data. However, they differ in how they store and access that data.

1. Array

Example:

        
let fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits[1]);
        
    

Output: Banana

2. Object

Example:

        
let person = { 
    name: "John", 
    age: 30,
    job: "Developer" };
console.log(person.name);
        
    

Output: John

Summary:

Aspect Array Object
Data Structure Ordered list Key-value pairs
Access By numeric index By key
Use Case Storing lists of items Representing structured data
Methods Array-specific methods like push, pop Object-specific methods like Object.keys, Object.values